<template>
  <view class="container">
    <view class="post-list">
      <view class="card post-item" v-for="post in posts" :key="post.id" @tap="goToDetail(post.id)">
        <view class="post-title">{{ post.title }}</view>
        <view class="post-meta">
          <text>作者：{{ post.author }}</text>
          <text class="dot">·</text>
          <text>{{ post.time }}</text>
        </view>
        <view class="post-actions">
          <view class="action-item">
            <text class="iconfont icon-like"></text>
            <text class="count">{{ post.likes }}</text>
          </view>
          <view class="action-item">
            <text class="iconfont icon-comment"></text>
            <text class="count">{{ post.comments }}</text>
          </view>
        </view>
      </view>
    </view>
    
    <view class="fab-button" @tap="goToCreate">
      <text>+ 发帖</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      posts: [
        {
          id: 1,
          title: '这是一个示例帖子标题',
          author: '张三',
          time: '2小时前',
          likes: 42,
          comments: 15
        },
        {
          id: 2,
          title: '另一个示例帖子标题',
          author: '李四',
          time: '3小时前',
          likes: 28,
          comments: 8
        }
      ]
    }
  },
  methods: {
    goToDetail(id) {
      uni.navigateTo({
        url: `/pages/post/detail?id=${id}`
      })
    },
    goToCreate() {
      uni.navigateTo({
        url: '/pages/post/create'
      })
    }
  },
  onPullDownRefresh() {
    // TODO: 实现下拉刷新
    setTimeout(() => {
      uni.stopPullDownRefresh()
    }, 1000)
  }
}
</script>

<style lang="scss">
@import '@/common/styles/common.scss';

.post-list {
  padding: 24rpx;
}

.post-item {
  .post-title {
    font-size: 32rpx;
    font-weight: bold;
    margin-bottom: 16rpx;
  }
  
  .post-meta {
    font-size: 24rpx;
    color: $text-color-secondary;
    margin-bottom: 16rpx;
    
    .dot {
      margin: 0 8rpx;
    }
  }
  
  .post-actions {
    display: flex;
    gap: 32rpx;
    
    .action-item {
      display: flex;
      align-items: center;
      color: $text-color-secondary;
      font-size: 24rpx;
      
      .iconfont {
        margin-right: 8rpx;
      }
    }
  }
}

.fab-button {
  position: fixed;
  right: 32rpx;
  bottom: 120rpx;
  background: $primary-color;
  color: #FFFFFF;
  padding: 16rpx 32rpx;
  border-radius: 32rpx;
  font-size: 28rpx;
  box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.1);
}
</style> 